package com.distribute.rest.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.distribute.rest.dao.JedisClient;
import com.distribute.rest.service.RedisService;
import com.distribute.common.pojo.DistributeResult;
import com.distribute.common.util.ExceptionUtil;
//同步缓存rest
@Service
public class RedisServiceImpl implements RedisService {

	@Autowired
	private JedisClient jedisClient;
	
	@Value("${INDEX_CONTENT_REDIS_KEY}")
	private String INDEX_CONTENT_REDIS_KEY;

	@Value("${REDIS_ITEM_KEY}")
	private String REDIS_ITEM_KEY;
	/*@Value("${REST_ITEM_BASEINFO_SYNC_URL}")
	private String REST_ITEM_BASEINFO_SYNC_URL;
	@Value("${REST_ITEM_DESC_SYNC_URL}")
	private String REST_ITEM_DESC_SYNC_URL;*/
	
	@Override
	public DistributeResult syncContent(long contentCid) {
		try {
			jedisClient.hdel(INDEX_CONTENT_REDIS_KEY, contentCid + "");
		} catch (Exception e) {
			e.printStackTrace();
			return DistributeResult.build(500, ExceptionUtil.getStackTrace(e));
		}
		return DistributeResult.ok();
	}

	@Override
	public DistributeResult syncItemBaseInfo(long itemId) {
		try {
			jedisClient.del(REDIS_ITEM_KEY + ":" + itemId+":base");
		} catch (Exception e) {
			e.printStackTrace();
			return DistributeResult.build(500, ExceptionUtil.getStackTrace(e));
		}
		return DistributeResult.ok();
		
	}

	@Override
	public DistributeResult syncItemDesc(long itemId) {
		try {
			jedisClient.del(REDIS_ITEM_KEY + ":" + itemId + ":desc");
		} catch (Exception e) {
			e.printStackTrace();
			return DistributeResult.build(500, ExceptionUtil.getStackTrace(e));
		}
		return DistributeResult.ok();
	}

}
